<?php

/**
 * @Author: Wang Chunsheng 2192138785@qq.com
 * @Date:   2020-03-14 23:43:15
 * @Last Modified by:   Wang Chunsheng 2192138785@qq.com
 * @Last Modified time: 2020-03-16 03:13:41
 */

use app\modules\diandi_shop\models\enums\OrderStatus;
use richardfan\widget\JSRegister;
use yii2mod\editable\EditableColumn;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model app\modules\diandi_shop\models\DdOrder */

$this->title = $model->order_id;
$this->params['breadcrumbs'][] = ['label' => 'Dd Orders', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<style>
    .box-title{
        font-size: 16px!important;
    }
</style>
<ul class="nav nav-tabs">
    <li>
        <?= Html::a('管理管理', ['index'], ['class' => '']) ?>
    </li>
    <li>
        <?= Html::a('添加订单', ['create'], ['class' => '']) ?>
    </li>
    <li class="active">
        <?= Html::a('订单处理', ['view'], ['class' => '']) ?>
    </li>
</ul>
<div class=" firetech-main">
    <div class="dd-order-view">

        <!-- <div class="panel panel-default"> -->
            <!-- <div class="box-body"> -->
                <div class="row">

                    <div class="col-md-6">
                        <div class="box">
                            <div class="box-header with-border">
                                <h4 class="box-title">
                                    <span class="fa fa-reorder"></span>
                                    订单信息
                                </h4>
                            </div>
                            <!-- /.box-header -->
                            <div class="box-body">
                                <?= DetailView::widget([
                                    'model' => $model,
                                    'options' => [
                                        'class' => 'table table-striped table-bordered detail-view',
                                    ],
                                    'attributes' => [
                                        // 'order_id',
                                        'order_no',
                                        [
                                            'label' => '订单状态',
                                            'attribute' => 'order_status',
                                            'filter' => Html::dropDownList('DdOrderSearch[order_status]', $searchModel->order_status, OrderStatus::listData(), [
                                                'prompt' => ['text' => '全部', 'options' => ['value' => '']],
                                                'class' => 'form-control'
                                            ]),
                                            'value' => function ($date) {
                                                return OrderStatus::getLabel($date->order_status);
                                            },
                                        ],
                                        'create_time:datetime',
                                        'total_price',
                                        'express_price',
                                        'pay_price',
                                        [
                                            'label' => '付款状态',
                                            'attribute' => 'pay_status',
                                            'value' => function ($date) {
                                                return $date->pay_status == 0 ? '未支付' : '已支付,支付时间：' . date('Y-m-d H:i:s', $date->pay_time);
                                            },
                                        ],
                                        [
                                            'label' => '发货状态',
                                            'attribute' => 'delivery_status',
                                            'value' => function ($date) {
                                                return $date->delivery_status == 0 ? '未发货' : '已发货,发货时间：' . date('Y-m-d H:i:s', $date->delivery_time);
                                            },
                                        ],
                                        [
                                            'label' => '收货状态',
                                            'attribute' => 'delivery_status',
                                            'value' => function ($date) {
                                                return $date->delivery_status == 0 ? '未收货' : '已收货,收货时间：' . date('Y-m-d H:i:s', $date->receipt_time);
                                            },
                                        ],
                                        [
                                            'class' => EditableColumn::class,
                                            'attribute' => 'remark',
                                            'url' => ['change-username'],
                                            'type' => 'select',
                                            'editableOptions' => function ($model) {
                                                return \yii2mod\editable\Editable::widget([
                                                    'model' => $model,
                                                    'attribute' => 'firstName',
                                                    'url' => '/profile/update',
                                                ]);
                                            },
                                        ],
                                        'user_id',
                                        'transaction_id',
                                        // 'express_company',
                                        // 'express_no',
                                        // 'delivery_status',
                                        // 'delivery_time:datetime',
                                        // 'receipt_status',
                                        // 'receipt_time:datetime',
                                        // 'order_status',                                      
                                        // 'wxapp_id',
                                        // 'update_time:datetime',
                                    ],
                                ]) ?>
                            </div>
                        </div>
                        <!-- /.box -->
                    </div>
                    <!-- /.col -->
                    <div class="col-md-6">
                    <div class="box">
                                <div class="box-header">
                                    <h4 class="box-title ">
                                        <span class="fa fa-cart-plus"></span>
                                        收货人信息
                                    </h4>
                                    <div class="box-tools">
                                        <a href="">编辑收货人信息</a>
                                    </div>
                                </div>
                                <!-- /.box-header -->
                                <div class="box-body padding">
                                    <div class="modal-info">
                                        <h5><?= $detail['address']['name'] . $detail['address']['phone'] ?></h5>
                                        <?= $detail['address']['detail'] ?>
                                    </div>

                                </div>
                                <!-- /.box-body -->
                            </div>

                        <div class="box">
                            <div class="box-header">
                                <h4 class="box-title">
                                    <span class="fa fa-user-plus"></span>
                                    商品信息
                                </h4>
                            </div>
                            <!-- /.box-header -->
                            <div class="box-body padding">

                                <table class="table table-striped">

                                    <tr>
                                        <th>商品图片</th>
                                        <th>商品名称</th>
                                        <th>重量(Kg)</th>
                                        <th>单价</th>
                                        <th>购买数量</th>
                                        <th>商品总价</th>
                                    </tr>
                                    <?php foreach ($detail['goods'] as $item) : ?>

                                        <tr>
                                            <td>
                                                <?= Html::img($item['thumb'], [
                                                    'alt' => 'My logo',
                                                    'style' => 'width:100px;',
                                                    'options' => []
                                                ]) ?>
                                            </td>
                                            <td><?= $item['goods_name'] ?></td>
                                            <td>
                                                <?= $item['goods_weight'] ?>
                                            </td>
                                            <td><?= $item['goods_price'] ?></td>
                                            <td><?= $item['total_num'] ?></td>
                                            <td>￥<?= $item['total_price'] ?></td>
                                        </tr>
                                    <?php endforeach; ?>
                                </table>
                            </div>
                            <!-- /.box-body -->
                        </div>


                        <div class="box-body" style='margin-top:20px;'>
                            <?php if($detail['order_status']==OrderStatus::getValueByName('未付款')): ?>   
                                <button type="button" class="btn btn-success pull-right" onclick="qrfk()">
                                    确认付款
                                </button>
                                <button type="button" class="btn btn-primary pull-right" style="margin-right: 5px;"  onclick="qxdd()">
                                    取消订单
                                </button>
                                <button type="button" class="btn btn-primary pull-right" style="margin-right: 5px;"  onclick="scdd()">
                                    删除订单
                                </button>
                            <?php elseif($detail['order_status']==OrderStatus::getValueByName('已付款')): ?>       
                                <button type="button" class="btn btn-primary pull-right" style="margin-right: 5px;" onclick="qrfh()">
                                    确认发货
                                </button>
                            <?php elseif($detail['order_status']==OrderStatus::getValueByName('已发货')): ?>       
                                <button type="button" class="btn btn-primary pull-right" style="margin-right: 5px;"  onclick="qesh()">
                                    确认收货
                                </button>
                            <?php endif; ?>  
                         
                        </div>

                        <!-- /.box -->
                    </div>
                    <!-- /.col -->

                </div>
                <!-- /.row -->
            </div>
        <!-- </div>
    </div> -->

<script>
    // 取消订单
    function qxdd(){
        $.ajax({
            type: 'POST',
            url: "<?= Url::toRoute(['order/dd-order/confirm'])?>",
            data: {
                'order_id':"<?= $detail['order_id'] ?>",
                'ctype':'qxdd'
                },
            dataType: 'json',
            success:function(res){
                if(res.code==200){
                   alert('取消成功') 
                   window.location.reload();
                }
                console.log(res)
            },
        });
    }
    
    // 删除订单
    
    function scdd(){
        $.ajax({
            type: 'POST',
            url: "<?= Url::toRoute(['order/dd-order/confirm'])?>",
            data: {
                'order_id':"<?= $detail['order_id'] ?>",
                'ctype':'scdd'
                },
            dataType: 'json',
            success:function(res){
                if(res.code==200){
                   alert('删除成功') 

                   $(window).attr('location',"<?= Url::toRoute(['order/dd-order'])?>");
                }
                console.log(res)
            },
        });
    }
    // 确认付款
    
    function qrfk(){
        $.ajax({
            type: 'POST',
            url: "<?= Url::toRoute(['order/dd-order/confirm'])?>",
            data: {
                'order_id':"<?= $detail['order_id'] ?>",
                'ctype':'qrfk'
                },
            dataType: 'json',
            success:function(res){
                if(res.code==200){
                   alert('付款成功') 
                   window.location.reload();
                }
                console.log(res)
            },
        });
    }
    // 确认收货
    
    function qrsh(){
        $.ajax({
            type: 'POST',
            url: "<?= Url::toRoute(['order/dd-order/confirm'])?>",
            data: {
                'order_id':"<?= $detail['order_id'] ?>",
                'ctype':'qrsh'
                },
            dataType: 'json',
            success:function(res){
                if(res.code==200){
                   alert('收货成功') 
                   window.location.reload();
                }
                console.log(res)
            },
        });
    }
    // 确认发货
    
      function qrfh(){
        $.ajax({
            type: 'POST',
            url: "<?= Url::toRoute(['order/dd-order/confirm'])?>",
            data: {
                'order_id':"<?= $detail['order_id'] ?>",
                'ctype':'qrfh'
                },
            dataType: 'json',
            success:function(res){
                if(res.code==200){
                   alert('发货成功') 
                   window.location.reload();
                }
                console.log(res)
            },
        });
    }
</script>